package jp.eisbahn.mgapi.api.updates;

import java.text.ParseException;
import java.util.Date;

import org.json.simple.JSONObject;

import jp.eisbahn.mgapi.api.Model;
import jp.eisbahn.mgapi.util.DateUtils;

/**
 * This class represents a feed.
 * @author Yoichiro Tanaka
 */
public class Entry extends Model {

    /** The object. */
    private ActivityObject object;

    /** The actor. */
    private ActivityObject actor;

    /**
     * Initialize this instance.
     * @param newOriginal The JSON object.
     */
    public Entry(final JSONObject newOriginal) {
        super(newOriginal);
        object = new ActivityObject(getPropertyJSONObject("object"));
        actor = new ActivityObject(getPropertyJSONObject("actor"));
    }

    /**
     * Retrieve a link.
     * @return The link string.
     */
    public final String getLink() {
        return getPropertyString("link");
    }

    /**
     * Retrieve a posted time.
     * @return The postedTime value as Date object.
     * @throws ParseException If the date string could not be parsed.
     */
    public final Date getPostedTime() throws ParseException {
        String postedTime = getPropertyString("postedTime");
        if (postedTime != null) {
            return DateUtils.convertDate(postedTime);
        } else {
            return null;
        }
    }

    /**
     * Retrieve a verb.
     * @return The verb string.
     */
    public final String getVerb() {
        return getPropertyString("verb");
    }

    /**
     * Retrieve an ID.
     * @return The ID string.
     */
    public final String getId() {
        return getPropertyString("id");
    }

    /**
     * Retrieve a title.
     * @return The title string.
     */
    public final String getTitle() {
        return getPropertyString("title");
    }

    /**
     * Retrieve an object.
     * @return The object.
     */
    public final ActivityObject getObject() {
        return object;
    }

    /**
     * Retrieve an actor.
     * @return The actor.
     */
    public final ActivityObject getActor() {
        return actor;
    }

}
